package org.jeecg.modules.third.jg.jss.report.cfccontractinfo.service;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.modules.third.jg.jss.report.cfccontractinfo.entity.CfcContractinfo;
import org.jeecg.modules.third.jg.jss.report.cfccontractinfo.mapper.CfcContractinfoMapper;
import org.jeecg.modules.wlhy.hyconfig.entity.HyConfig;
import org.jeecg.modules.wlhy.utils.HyConfigUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @Description: CFC_CONTRACTINFO
 * @Author: jeecg-boot
 * @Date:   2021-11-25
 * @Version: V1.0
 */
@Service
@Slf4j
public class CfcContractinfoService{


    @Resource
    private CfcContractinfoMapper contractinfoMapper;

    //private String DOMAIN =  "https://n.mabond56.com" ;


    @Value(value="${server.port}")
    private String port;

    @Value(value="${server.servlet.context-path}")
    private String path;

    @Value(value="${js-report-platform.wlhydomain:}")
    private String wlhydomain;

    public CfcContractinfo insertContractinfo(CfcContractinfo cfcContractinfo) {
        contractinfoMapper.insertContractinfo( cfcContractinfo );
        return cfcContractinfo;
    }



    public CfcContractinfo getContractinfoByNumber(String contractnumber) {
        return contractinfoMapper.getContractinfoByNumber( contractnumber );
    }


    public Integer deleteContractinfo(String contractnumber) {
        return contractinfoMapper.deleteContractinfo( contractnumber );
    }

    /**
     * 获取合同查看地址
     *
     * @param contractAdd
     * @return
     */
    public String getContractAdd(String contractAdd) {
        if (StringUtils.isEmpty(contractAdd)) {
            return StringUtils.EMPTY;
        }

//        HyConfig systemConfig = HyConfigUtils.getConfig();
//        if (systemConfig == null || !systemConfig.getJsReportIzUse()) {
//            return StringUtils.EMPTY;
//        }

        try {
            //String ip = InetAddress.getLocalHost().getHostAddress();
            //String url =  systemConfig.getJsDomain()+"/wlhy168/generic/web/viewer.html?file="+systemConfig.getJsDomain()  + path   +"/sys/common/static/" +contractAdd;
            String url = wlhydomain + path + "/sys/common/static/" + contractAdd;
            return url;
        } catch (Exception e) {
            log.error(e.getMessage());
        }
        return StringUtils.EMPTY;
    }
}
